﻿using System;
using System.Collections;
using System.Reflection;

namespace SimpleORM
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
    public sealed class TypeConverterAttribute : Attribute
    {
        public Type Target { get; private set; }

        public TypeConverterAttribute(Type target)
        {
            this.Target = target;
        }

        public static Hashtable Create(Type type)
        {
            Hashtable ht = new Hashtable();

            MethodInfo[] listMethods = type.GetMethods();

            foreach (MethodInfo mi in listMethods)
            {
                TypeConverterAttribute[] attrs = mi.GetAttributes<TypeConverterAttribute>();

                foreach (TypeConverterAttribute attr in attrs)
                    ht[attr.Target] = mi;
            }

            return ht;
        }
    }

}